package com.morningstar.system.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.morningstar.common.result.ServiceCheckResult;
import com.morningstar.system.dao.entity.SysDictType;
import com.morningstar.system.dao.mapper.SysDictTypeMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 字典 业务层处理
 *
 * @author ruoyi
 */
@Slf4j
@Service
public class SysDictTypeService extends ServiceImpl<SysDictTypeMapper, SysDictType> {


    public ServiceCheckResult checkAddAndUpdate(SysDictType sysDictType) {
        LambdaQueryWrapper<SysDictType> checkDictNameWrapper = new LambdaQueryWrapper<SysDictType>()
                .eq(SysDictType::getDictName, sysDictType.getDictName())
                .ne(sysDictType.getDictId() != null, SysDictType::getDictId, sysDictType.getDictId());
        if (this.count(checkDictNameWrapper) > 0) {
            return new ServiceCheckResult(true, "字典名称已存在");
        }
        LambdaQueryWrapper<SysDictType> checkDictTypeWrapper = new LambdaQueryWrapper<SysDictType>()
                .eq(SysDictType::getDictType, sysDictType.getDictType())
                .ne(sysDictType.getDictId() != null, SysDictType::getDictId, sysDictType.getDictId());
        if (this.count(checkDictTypeWrapper) > 0) {
            return new ServiceCheckResult(true, "字典类型已存在");
        }
        return new ServiceCheckResult(false);
    }
}
